/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.mail.domain;

import info.peigen.hotpot.common.core.domain.DomainObject;
import info.peigen.hotpot.component.mail.service.order.AbstractMailServiceOrder;
import jakarta.validation.constraints.NotEmpty;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;

import java.util.List;

/**
 * <b>(Mail)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/1/19
 */
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
public class Mail extends DomainObject {
    /** 邮件主题 */
    @NotEmpty
    String       subject;
    /** 发件人 */
    @NotEmpty
    String       from;
    /** 收件人 */
    @NotEmpty
    List<String> to;
    /** 抄送给某人 */
    List<String>         cc;
    /** 秘密抄送给某人 */
    List<String>         bcc;
    /** 邮件体 */
    String               context;
    /** 模版 */
    MailTemplate         mailTemplate;
    /** 附件 */
    List<MailAttachment> mailAttachments;

    public static Mail create(AbstractMailServiceOrder order) {
        return Mail.builder().from(order.getFrom()).to(order.getTo()).cc(order.getCc()).bcc(order.getBcc()).build();
    }
}
